package com.bangcommunity.bbframe.sdm.web.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextListener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by tanghc on 2016/3/30.
 */
public class CustomRequestContextListener extends RequestContextListener {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void requestInitialized(ServletRequestEvent requestEvent) {
        logger.debug("========== monitor ====  request  ==========");
        if (!(requestEvent.getServletRequest() instanceof HttpServletRequest)) {
            throw new IllegalArgumentException("CustomRequestContextListener Request is not an HttpServletRequest: "
                    + requestEvent.getServletRequest());
        }
        HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest();
        // RequestContextAttributeHolder.setRequestAttributes(baseParam);
        super.requestInitialized(requestEvent);
    }

    @Override
    public void requestDestroyed(ServletRequestEvent requestEvent) {
        // logger.debug("CustomRequestContextListener requestDestroyed "+
        // RequestContextAttributeHolder.getRequestAttributes());
        // RequestContextAttributeHolder.resetRequestAttributes();
        super.requestDestroyed(requestEvent);
    }
}
